package com.pw.canbuslogger;

import java.util.Queue;

import com.pw.canbuslogger.view.grid.ICANBusRecordProcessor;

public class CANBusDataWriter implements Runnable {

	private final Queue<Object[]> queue;
	private final ICANBusRecordProcessor recordProcessor;

	public CANBusDataWriter(Queue<Object[]> queue, ICANBusRecordProcessor recordProcessor) {
		this.queue = queue;
		this.recordProcessor = recordProcessor;
	}

	@Override
	public void run() {
		while (true) {
			Object[] rec = queue.poll();
			if (rec != null) {
				recordProcessor.accept(rec);
			} else {
				try {
					Thread.currentThread().sleep(20);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}

	}

}
